var a = getApp();

Page({
    data: {
        display: "none",
        dynamicId: 0,
        userAccessToken: "",
        name: "",
        avatar: "",
        submitTime: "",
        teamId: "",
        teamName: "",
        attention: 0,
        dynamicType: 0,
        autoplay: !1,
        width: 0,
        height: 0,
        images: [],
        content: "",
        teletexts: [],
        title: "",
        commentPageNo: 1,
        comments: [],
        zanPageNo: 1,
        zanFirstLoad: !0,
        zans: [],
        zan: 0,
        collect: 0,
        currentTab: 0,
        videoUrl: "",
        fromShare: !1,
        weixinProgramShareInfo: {}
    },
    onLoad: function(t) {
        var e = !1;
        void 0 != t.fromTo && (e = !0), this.setData({
            dynamicId: t.dynamicId,
            fromShare: e
        }), a.util.openSharePage(t);
    },
    bindCommentTabTap: function() {
        this.setData({
            currentTab: 0
        });
    },
    bindZanTabTap: function() {
        this.setData({
            currentTab: 1
        }), 0 != this.data.zanCount && 0 == this.data.zans.length && this.loadZanListData(!0);
    },
    clickCollcet: function(t) {
        var e = this;
        a.network.post({
            url: a.url.dynamicCollect,
            params: {
                dynamicId: e.data.dynamicId
            },
            before: function() {
                e.setData({
                    collect: 1
                });
            },
            success: function(t) {
                1 == t.data.result ? a.util.showToast("收藏成功") : (a.util.showToast(t.data.message), 
                e.setData({
                    collect: 0
                }));
            },
            fail: function() {
                a.util.showToast("收藏失败"), e.setData({
                    collect: 0
                });
            },
            complete: function() {}
        });
    },
    clickUnCollcet: function(t) {
        var e = this;
        a.network.post({
            url: a.url.dynamicUnCollect,
            params: {
                dynamicId: e.data.dynamicId
            },
            before: function() {
                e.setData({
                    collect: 0
                });
            },
            success: function(t) {
                1 == t.data.result || (a.util.showToast(t.data.message), e.setData({
                    collect: 1
                }));
            },
            fail: function() {
                a.util.showToast("取消收藏失败"), e.setData({
                    collect: 1
                });
            },
            complete: function() {}
        });
    },
    clickBack: function(t) {
        var e = a.util.isLogin() ? "/pages/schedule/schedule" : "/pages/hysquare/hysquare";
        wx.reLaunch({
            url: e
        });
    },
    clickTeam: function(t) {
        a.util.navToTeamHome(this.data.teamId);
    },
    bindBigImageTap: function(a) {
        for (var t = this.data, e = [], n = 0; n < t.images.length; n++) e[n] = t.images[n].bigImage;
        1 == t.images.length ? wx.previewImage({
            current: e[0],
            urls: e
        }) : wx.previewImage({
            current: a.currentTarget.dataset.image,
            urls: e
        });
    },
    bindTeleTextBigImageTap: function(a) {
        for (var t = a.currentTarget.dataset.image, e = [], n = this.data.teletexts, o = 0; o < n.length; o++) {
            var i = n[o];
            "1" == i.type && e.push(i.bigImage);
        }
        wx.previewImage({
            current: t,
            urls: e
        });
    },
    bindCommentTap: function() {
        a.util.isLoginModal() && wx.navigateTo({
            url: "dynamicComment/dynamicComment?commentType=0&dynamicId=" + this.data.dynamicId
        });
    },
    bindZanTap: function() {
        if (a.util.isLoginModal()) {
            var t = this;
            1 == t.data.zan ? a.network.post({
                url: a.url.hunyuCycleZan,
                params: {
                    dynamicId: t.data.dynamicId,
                    zan: 0
                },
                before: function() {
                    var a = t.data.zanCount - 1;
                    t.setData({
                        zan: 0,
                        zanCount: a
                    });
                },
                success: function(e) {
                    if (1 == e.data.result) a.util.showToast("取消赞成功"); else {
                        a.util.showToast(e.data.message);
                        var n = t.data.zanCount + 1;
                        t.setData({
                            zan: 1,
                            zanCount: n
                        });
                    }
                },
                fail: function() {
                    a.util.showToast("取消赞失败");
                    var e = t.data.zanCount + 1;
                    t.setData({
                        zan: 1,
                        zanCount: e
                    });
                },
                complete: function() {}
            }) : a.network.post({
                url: a.url.hunyuCycleZan,
                params: {
                    dynamicId: t.data.dynamicId,
                    zan: 1
                },
                before: function() {
                    var a = t.data.zanCount + 1;
                    t.setData({
                        zan: 1,
                        zanCount: a
                    });
                },
                success: function(e) {
                    if (1 == e.data.result) a.util.showToast("赞成功"); else {
                        a.util.showToast(e.data.message);
                        var n = t.data.zanCount - 1;
                        t.setData({
                            zan: 0,
                            zanCount: n
                        });
                    }
                },
                fail: function() {
                    a.util.showToast("赞失败");
                    var e = t.data.zanCount - 1;
                    t.setData({
                        zan: 0,
                        zanCount: e
                    });
                },
                complete: function() {}
            });
        }
    },
    loadCommentListData: function(t) {
        var e = this, n = e.data.commentPageNo;
        if (t) n = 1; else if (e.data.commentCount == e.data.comments.length) return;
        a.network.post({
            url: a.url.hunyuCycleCommentList,
            params: {
                pageNo: n,
                pageSize: 10,
                dynamicId: e.data.dynamicId
            },
            before: function() {
                wx.showNavigationBarLoading();
            },
            success: function(o) {
                if (1 == o.data.result) {
                    var i = [];
                    t || (i = e.data.comments), i = i.concat(o.data.data.dynamicComments);
                    for (var s = 0; s < i.length; s++) a.globalData.accessToken == e.data.userAccessToken || a.globalData.accessToken == i[s].commentAccessToken ? i[s].del = !0 : i[s].del = !1;
                    n += 1, e.setData({
                        commentCount: o.data.data.total,
                        comments: i,
                        commentPageNo: n
                    });
                } else a.util.showToast(o.data.message);
            },
            fail: function() {
                a.util.showToast("获取数据失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
            }
        });
    },
    bindCommentReplyTap: function(t) {
        if (a.util.isLoginModal()) {
            var e = t.currentTarget.dataset.commentid;
            wx.navigateTo({
                url: "dynamicComment/dynamicComment?commentType=1&dynamicCommentId=" + e
            });
        }
    },
    bindCommentDelTap: function(t) {
        var e = t.currentTarget.dataset.commentid, n = this;
        wx.showModal({
            title: "提示",
            content: "确定删除此条评论?",
            confirmText: "删除",
            confirmColor: a.globalData.themeColor,
            success: function(t) {
                t.confirm ? a.network.post({
                    url: a.url.deleteDynamicComment,
                    params: {
                        dynamicCommentId: e
                    },
                    before: function() {
                        wx.showLoading({
                            title: "提交数据"
                        });
                    },
                    success: function(t) {
                        1 == t.data.result ? (a.util.showToast(t.data.message), n.loadCommentListData(!0)) : a.util.showToast(t.data.message);
                    },
                    fail: function() {
                        a.util.showToast("提交数据失败");
                    },
                    complete: function() {
                        wx.hideLoading();
                    }
                }) : t.cancel;
            }
        });
    },
    bindCommentUserTap: function(t) {
        var e = t.currentTarget.dataset.accesstoken;
        a.util.navToUserHome(e);
    },
    loadZanListData: function(t) {
        var e = this, n = e.data.zanPageNo;
        if (t) n = 1; else if (e.data.zanCount == e.data.zans.length) return;
        a.network.post({
            url: a.url.hunyuCycleZanList,
            params: {
                pageNo: n,
                pageSize: 10,
                dynamicId: e.data.dynamicId
            },
            before: function() {
                wx.showNavigationBarLoading();
            },
            success: function(o) {
                if (1 == o.data.result) {
                    var i = [];
                    t || (i = e.data.zans), i = i.concat(o.data.data.dynamicZans), n += 1, e.setData({
                        zanCount: o.data.data.total,
                        zans: i,
                        zanPageNo: n
                    });
                } else a.util.showToast(o.data.message);
            },
            fail: function() {
                a.util.showToast("获取数据失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
            }
        });
    },
    onReady: function() {
        var t = this;
        a.network.post({
            url: a.url.dynamicDetail,
            params: {
                dynamicId: t.data.dynamicId
            },
            before: function() {
                wx.showNavigationBarLoading(), wx.showLoading({
                    title: "加载中"
                });
            },
            success: function(e) {
                if (1 == e.data.result) {
                    var n = e.data.data;
                    t.setData({
                        userAccessToken: n.userAccessToken,
                        avatar: n.avatar,
                        name: a.util.getRoleName(n.role) + " " + n.name,
                        submitTime: n.submitTime,
                        teamId: n.teamId,
                        teamName: n.teamName,
                        attention: n.attention,
                        dynamicType: n.type,
                        content: n.content ? n.content : "",
                        width: n.width ? n.width : 0,
                        height: n.height ? n.height : 0,
                        images: n.images ? n.images : [],
                        teletexts: n.teletexts ? n.teletexts : [],
                        title: n.title ? n.title : "",
                        commentCount: n.commentCount,
                        zanCount: n.zanCount,
                        zan: n.zan,
                        collect: n.collect,
                        videoUrl: n.url ? n.url : "",
                        weixinProgramShareInfo: n.weixinProgramShareInfo
                    }), n.commentCount > 0 && t.loadCommentListData(!0), setTimeout(function() {
                        t.setData({
                            submitTime: n.submitTime
                        });
                    }, 1e3);
                } else a.util.showToast(e.data.message);
            },
            fail: function() {
                a.util.showToast("获取数据失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading(), t.setData({
                    display: "flex"
                }), wx.hideLoading();
            }
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        0 == this.data.currentTab ? this.loadCommentListData(!1) : 1 == this.data.currentTab && this.loadZanListData(!1);
    },
    onShareAppMessage: function() {
        return {
            title: this.data.weixinProgramShareInfo.shareTitle,
            path: this.data.weixinProgramShareInfo.shareUrl,
            imageUrl: this.data.weixinProgramShareInfo.shareImage,
            success: function(a) {},
            fail: function(a) {}
        };
    }
});